<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<base href="<%=basePath%>">

<title>确认订单</title>

<link rel="stylesheet" href="css/xiadan.css?a=<%=new Date().getTime()%>" />
<link rel="stylesheet" type="text/css" href="css/gouwuche1.css?a=<%=new Date().getTime()%>" />
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/gouwuche1.js"></script>
<script type="text/javascript" src="js/distpicker.data.js"></script>
<script type="text/javascript" src="js/Address.js?_<%=new Date().getTime() %>"></script>
<script type="text/javascript" src="js/distpicker.js"></script>
<script>
		function addadd(){
			/* $("#xiugaidizhi").slideDown(); */
		    $("#shou1").slideDown(300);
		    $(".black1").show();
		}
		function xiadan(){
			var name=$(".name").val();
			var phone=$(".phone").val();
			var save=$(".sheng").val();
			var city=$(".shi").val();
			var county=$(".xian").val();
			var info=$(".di").val;
			if(name!=null && phone!=null && save!=null && city!=null && county!=null && info!=null){
				$("#from").val(window.location.href);
				$("#addadd").submit();
				return false;
			}
		}
		function dianjiyixai() {
			$("#from").val(window.location.href);
			var name=$(".name").val();
			var phone=$(".phone").val();
			var xiangxi=$(".xiangxi").val();
			var bianma=$(".bianma").val();
			if(name==null || name=="" && phone==null || phone=="" && xiangxi==null || xiangxi=="" && bianma==null || bianma==""){
				alert("请仔细填写");
				return false;
			}else{
				$("#myform1").submit();
			}
		}
		//判断是否为空
		function checkPhone2(){
		    var $user2 = $("#xiangXi1");
		    var $divID2 = $("#divMobile2");
		    var $user1 = $("#phone");
		    var $divID1 = $("#divMobile1");
		    var $user = $("#mobile");
		    var $divID = $("#divMobile");
		    $divID.html("");
		    if($user.val() == "") {
		        $divID.html("名字不能为空！");
		        $user.css('border','1px solid red')
		        return false;
		    }else if ($user.val().length < 2) {
		        $divID.html("你输入的姓名格式不对！");
		        $user.css('border','1px solid red')
		        return false;
		    }else  if($user1.val() == "") {
		        $divID1.html("手机号码不能为空！");
		        $user1.css('border','1px solid red')
		        return false;
		    }else if($user1.val().length < 11) {
		        $divID1.html("手机号码必须是11个字符,请重新输入！");
		        $user1.css('border','1px solid red')
		        return false;
		    }else if ($user2.val() == "") {
		        $divID2.html("邮箱不能为空！");
		        $user2.css('border','1px solid red')
		        return false;
		    }
		    return true;
		}
		//信息
		$(function(){
			var sid=$("#sid").val();
			var addid=$("#shoppingcarid").val();
			$("#shoppingcarid12").val(addid);
			/* $("#shoppingcarid").val();
			var images="";
			var mingcheng="";
			var shuliang="";
			var chima="";
			var jine="";
			var length=$(".sp").length;
			for (var i = 0; i <length; i++) {
				var img=$(".spimg img:eq("+i+")").attr("src");
				images+=img+",";
				var name=$(".spname:eq("+i+")").text();
			    mingcheng+=name+",";
			 	var num=$(".num:eq("+i+")").text();
			 	shuliang+=num+",";
			 	var size=$(".size:eq("+i+")").text();
			 	chima+=size+",";
			 	var money=$(".money:eq("+i+")").text();
			 	jine+=money+",";
			} 
			var sbimg=images.substring(0,images.lastIndexOf(","));
		    var sbname=mingcheng.substring(0,mingcheng.lastIndexOf(","));
		    var sbshuliang=shuliang.substring(0,shuliang.lastIndexOf(","));
		    var sbchima=chima.substring(0,chima.lastIndexOf(","));
		    var sbjine=jine.substring(0,jine.lastIndexOf(","));
			$("#img").val(sbimg);
			$("#name").val(sbname);
			$("#num").val(sbshuliang);
			$("#size").val(sbchima);
			$("#money").val(sbjine); */
			/* $(".spimg img").each(function(){
				var a=$(this).attr("src");
				$("#tupian").val(a);
				alert($("#tupian").val());
			}) */
		//计算总件数总金额
			/* var length=$(".sp").length;
			var nums=$(".num").text();
			var prices=$(".spprice").text();
			var sums=prices.split("元");
			var zongnum=0;
			var zongsum=0;
			for(var i=0;i<length;i++){
				var sum=sums[i];
				var num=nums.substr(i,i+1);
				zongnum+=eval(num);
				zongsum+=eval(sum);
			}
			$(".nums").text(zongnum+"件");
			$(".prices").text(zongsum+"元");
			$("#jine #price").text(zongsum+"元");
			$("#spjine").val(zongsum); */
			//总金额
			var moneya=0;
			$("#spneirong #zongmoney").each(function(){
				var aa=$(this).text();
				moneya+=eval(aa);
				$("#price").text(moneya+".00 ");
			})
			//数量
			var shuliang=0;
			$("#spneirong .num").each(function(){
				var aa=$(this).text();
				shuliang+=eval(aa);
				$(".nums").text(shuliang+" 件");
			})
			//编辑地址
		  	$("#shou").hide();
	        $(".black").hide();
	        $("#myform").submit(function () {
		        var flag = true;
		        if (!checkPhone2()) flag = false;
		        return flag;
	        });
	        $("#quxiao").bind("click",function () {
	            $("#shou").slideUp(300);
	            $(".black").hide();
	        })
	         //增加地址
		  	$("#shou1").hide();
	        $(".black1").hide();
	       /*  $("#myform1").submit(function () {
		        var flag = true;
		        if (!checkPhone2()) flag = false;
		        return flag;
	        }); */
	        /* $(".tanchu").bind("click",function(){
	            $("#shou1").slideDown(300);
	            $(".black1").show();
	        }); */
	
	        $("#quxiao1").bind("click",function () {
	            $("#shou1").slideUp(300);
	            $(".black1").hide();
	        })
	         $("#xiugai1").click(function() {
	        	 var sheng= $("select").eq(3).val();
	        	 var shi = $("select").eq(4).val();
	        	 var xian = $("select").eq(5).val();
	        	 $("#sheng1").val(sheng);
	        	 $("#shi1").val(shi);
	        	 $("#xian1").val(xian);
	         })
		})
		function jiesuan(){
			//总价
			var p=$("#price").text();
			$("#totalmoney").val(p);
			var shohuo=$("#shouhuo").val();
			if(shohuo==null || shohuo==""){
				alert("请选择收货地址!");
				return false;
			}else{
				$("#formbiao").submit();
			}
			
			
		}
		function dizhi(id,ts){
			$(ts).addClass("ave").siblings().removeClass("ave");
			$("#shouhuo").val(id);
			var name=$(ts).children("p:first").text();
			$("#shouname").val(name);
			var ss=$(ts).text();
			var name=$(ts).children(":first").next().text();
			var phone=$(ts).children(":first").next().next().text();
			var address=$(ts).children(":first").next().next().next().text();
			var addresss=$(ts).children(":first").next().next().next().next().text();
			$("#jiesuan p").html(name+"---"+phone+"---"+address+"---"+addresss);
			$("#usename").val(name);
			$("#phone").val(phone);
			$("#ssxx").val(address+" "+addresss);
		}
		function  setssid() {
			var len=$(".sp").length;
			var a="";
			for(var i=0;i<len;i++){
			a+=$(".sid:eq("+i+")").val();
			a+=",";
			}
			$("#hiddenssid").val(a);
		}
		function del(delid,ts){
			$.post("ajaxdelShoppingAddress.shtml",{"delid":delid},function(date){
				if(date=="true"){
					alert("删除成功");
					$(ts).parent().parent().parent().remove();
				}else{
					alert("删除失败");
				}
			})
		}
		//点击编辑修改地址
		function bianji(bianjiid,ts){
			//弹出框
			$("#shou").slideDown(300);
	        $(".black").show();
	     	//获取地址
	        var sheng = $(ts).parents(".dizhikuan").find(".shengsheng").text();
			var shi = $(ts).parents(".dizhikuan").find(".shishi").text();
			var xian = $(ts).parents(".dizhikuan").find(".xianxian").text();
			$.post("readAddressbianji.shtml",{"bianjiid":bianjiid},function(date){
				var x=date.split(",");
				$("#mobile").val(x[0]);
				$("#phone12").val(x[1]);
				$("#xiangXi1").val(x[2]);
				$("#xiangXi").val(x[3]);
				$("#bianid").val(x[4]);
				$(".bianjiid").val(bianjiid);
				
				$(".info1 #area select").eq(0).val(sheng).trigger("change");
				$(".info1 #area select").eq(1).val(shi).trigger("change");
				$(".info1 #area select").eq(2).val(xian);
				/* var a=$(".bianjiid").val();
				alert(a); */
				/* var shengsheng=($(".info1 #area select").eq(0).val());
				var shishi=$(".info1 #area select").eq(1).val();
				var xianxian=$(".info1 #area select").eq(2).val();
				$("#shengsheng1").val(shengsheng);
				$("#shishi1").val(shishi);
				$("#xianxian1").val(xianxian); */
			
			}) 
		}
		function querenxiugai(){
			$("#from1").val(window.location.href);
			var shengsheng=($(".info1 #area select").eq(0).val());
			var shishi=$(".info1 #area select").eq(1).val();
			var xianxian=$(".info1 #area select").eq(2).val();
			$("#querensheng").val(shengsheng);
			$("#querenshi").val(shishi);
			$("#querenxian").val(xianxian);
		}
		</script>
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script type="text/javascript" src="js/xiadan.js?_<%=new Date().getTime()%>"></script>
</head>

<body>
<div class="beihui">
	<div id="da">
		<div id="shang">
			<div id="baos">
				<div class="szuo">
					<img src="images/index/logo.png" align="center" />
				</div>
				<div class="szhong">
					确认订单
				</div>
			</div>
		</div>
		<!-- 中间块 -->
		<div id="zhong">
			<!-- 中间块 白色背景部分 -->
			<div id="bai">
				<div id="dizhi">
					<p id="wenzi">收货地址</p>
					
					<c:if test="${sAddresses!=null}"><p>${ss }</p></c:if>
					<c:forEach items="${sAddresses }" var="addlist">
						<div class="dizhikuan" onclick="dizhi(${addlist.sa_id},this)">
							<p><input type="hidden" value="${addlist.sa_id}" name="id" /></p>
							<p class="dizhiname">${addlist.getSa_name() }</p>
							<p class="dizhiphone">${addlist.sa_phone }</p>
							<p class="dizhicity"><span class="shengsheng">${addlist.sa_sheng }</span>&emsp;<span class="shishi">${addlist.sa_shi }</span>&emsp;<span class="xianxian">${addlist.sa_xian }</span></p>
							<p class="dizhiinfo">${addlist.sa_address }</p> 
							<p style="margin-left: 160px;margin-top: -10px;	">
								<span><a href="javascript:void(0)"  style="text-decoration: none; color:#343434;" class="tanchu" onclick="bianji(${addlist.sa_id},this)">编辑</a></span>
								<span style="margin-left:20px;"><a href="javascript:void(0)"  style="text-decoration: none; color:#343434;" onclick="del(${addlist.sa_id},this)">删除</a></span>
							</p>
						</div>
					</c:forEach>
					<div class="dizhikuan" onclick="addadd()">
						<p class="addadd" style="display: none">添加新地址</p>
						<p class="tu"><img src="images/悬浮前.jpg" alt="" /></p>
						<p class="di">添加新地址</p>
					</div>
				</div>
				<div class="clear:both;"></div>
				<div id="spkuai">
					<h2 id="youhuiquan">
						商品及优惠券<span>返回购物车</span>
					</h2>
					<div id="spneirong">
						<ul>
							<c:forEach items="${shoppingCars }" var="sh">
								<li style="line-height: 50px; height: 70px;" class="sp">
									<input type="hidden" value="${sh.sc_scid }" name="" id="sid" class="sid"/><!--商品的id  -->
									<span><input type="hidden" value="${sh.sc_id }" id="shoppingcarid"/></span>
									<span class="spimg"><img src="${sh.sc_images }" alt=""width="50px" height="50px" style="margin-left: 30px;" /></span> 
									<span class="spname" style="margin-left: 100px;">${sh.sc_name }</span>
									<span class="size" style=" width:30px;margin-left: 500px;">${sh.sc_size }</span>
									<span style="margin-left: 100px;">￥<span class="money">${sh.sc_price }</span></span>
									<span style="margin-left: 100px;" class="num">${sh.sc_num }</span>
									<span style="margin-left: 100px;" ><span id="zongmoney">${sh.sc_price * sh.sc_num }</span>0元</span>
									
								</li>
							</c:forEach>
						</ul>
									
									
					</div>
					<div id="dingdaninfo">
						<ul>
							<li>商品件数: <span class="nums">0件</span></li>
							<li id="jine">应付总额: <span id="price">00.00</span>元</li>
						</ul>
					</div>
					<div id="jiesuan">
						<p style="float: left"></p>
						<form action="BuyShoppingSuccess.shtml" method="post" id="formbiao" onsubmit="setssid()">
							<input type="hidden" value="" name="usename" id="usename" />
							<input type="hidden" value="" name="phone" id="phone" />
							<input type="hidden" value="" name="ssxx" id="ssxx" />
							<input type="hidden" id="sssid" value="" name="sssid" />
							<input type="hidden" name="ssid" value="" id="hiddenssid"/>
							<input type="hidden" value="" id="shoppingcarid12" name="shoppingcarid" />
							<input type="hidden" value="" id="totalmoney" name="totalmoney" />
							<input type="hidden" name="name" id="shouname" value="" /> 
							<input type="hidden" name="shouhuo" id="shouhuo" value="" /> 
							<input type="hidden" name="spjine" id="spjine" value="" /> 
							<input type="hidden" name="spid" id="spid" value="${id }" /> 
							<input type="button" value="去结算" id="btnjie" onclick="jiesuan()" />
						</form>
					</div>
				</div>

			</div>
		</div>
	</div>
		 	</div>
		 	
		 	 <!-- 编辑地址 -->
			 <div class="bj"></div>
			 <div class="black"></div>
			 <div id="shou">
		        <h2><span>编辑收货地址</span></h2>
		        <div class="info1">
		            <form action="xiadanbianjiaddress.shtml" method="post" id="myform">
		            <p><input type="hidden" name="sheng1" class="sheng" id="shengsheng1"  value="" />
			            <input type="hidden" name="shi1" class="shi" id="shishi1"  value="" />
			            <input type="hidden" name="xian1" class="xian" id="xianxian1"  value="" /></p>
			            <p><input type="hidden" class="bianjiid" value="" name="bianjiid" /></p>
			            <input type="hidden" value="" id="querensheng" name="querensheng" />
			            <input type="hidden" value="" id="querenshi" name="querenshi" />
			            <input type="hidden" value="" id="querenxian" name="querenxian" />
		                <p>姓名<span>*</span><input type="text" id="mobile" name="name" style="font-size: 11px;" value="" placeholder="请输入姓名" maxlength="15" id="user"/><span id="divMobile"></span>
		                	手机号<span>*</span><input type="text" id="phone12" name="phone" style="font-size: 11px;" value="" placeholder="请输入11位手机号" maxlength="11"/><span id="divMobile1"></span>
		                <div id="area">地址<span>*</span></div>
		                <p class="xxxx">详细信息<span>*</span><input type="text" id="xiangXi" name="xiangxi" value="" style="font-size: 11px;" placeholder="请输入详细地址，例如路名、门牌号"/></p>
		                <p class="yz">邮政编码<span>*</span><input type="text" id="xiangXi1" name="bianhao" value="" style="font-size: 11px;" placeholder="请输入你的邮政编码"/><span id="divMobile2"></span></p>
		               	<input type="hidden" name="from1" id="from1" />
		                <p class="qr"><input type="submit" class="queding1" value="确认修改" id="xiugai" onclick="querenxiugai()" /><input type="button" id="quxiao" value="取消"/></p>
		            </form>
		        </div>
		    </div>
		    <!-- 增加地址 -->
			<div class="bj1"></div>
			 <div class="black1"></div>
			 <div id="shou1">
		        <h2><span>增加收货地址</span></h2>
		        <div class="info11">
		            <form action="oxiadanAddress.shtml" method="post" id="myform1">
		            	<p><input type="hidden" name="sheng1" id="sheng1" class="sheng"  value="" />
			            <input type="hidden" name="shi1" id="shi1" class="shi"  value="" />
			            <input type="hidden" name="xian1" id="xian1" class="xian"  value="" /></p>
			            <p><input type="hidden" class="bianjiid1" value="" name="bianjiid" /></p>
		                <p>姓名<span>*</span><input type="text" id="mobile" class="name" name="name1" style="font-size: 11px;" value="" placeholder="请输入姓名" maxlength="15" id="user"/><span id="divMobile"></span>
		                	手机号<span>*</span><input type="text" id="phone" class="phone" name="phone1" style="font-size: 11px;" value="" placeholder="请输入11位手机号" maxlength="11"/><span id="divMobile1"></span>
		                <div class="area" id="area">地址<span>*</span></div>
		                <p class="xxxx">详细信息<span>*</span><input type="text" id="xiangXi" class="xiangxi" name="xiangxi1" value="" style="font-size: 11px;" placeholder="请输入详细地址，例如路名、门牌号"/></p>
		                <p class="yz">邮政编码<span>*</span><input type="text" id="xiangXi1" class="bianma" name="bianhao1" value="" style="font-size: 11px;" placeholder="请输入你的邮政编码"/><span id="divMobile2"></span></p>
		                <input type="hidden" name="from" id="from" />
		                <p class="qr"><input type="button"  value="增加地址" id="xiugai1" onclick="dianjiyixai()"/><input type="button" id="quxiao1" value="取消"/></p>
		            </form>
		        </div>
		    </div>
</body>
</html>